// import { initData } from "../view/ota/constance";
import { makeAutoObservable } from "mobx";
import { Store } from ".";

export type ParamType = {
  date: string;
  location: Location;
};

export type Location = {
  from: string;
  to: string;
};

export class SearchParam {
  public state: ParamType = {
    location: {
      from: "",
      to: "",
    },
    date: "",
  };
  constructor() {
    makeAutoObservable(this);
  }
  setSearchParam(param: ParamType) {
    this.state = {
      ...this.state,
      ...param,
    };
  }
  setSearchDate(date: string) {
    console.log("setSearchDate");

    this.state = {
      ...this.state,
      date: date,
    };
  }
  get location() {
    return this.state.location;
  }
}

export const getSearchParam = (store: Store) => store.searchParam.state;
export const getSearchLocation = (store: Store) =>
  store.searchParam.state.location;
